$(function (){
	try{
		CheckUseTimeStr();
	}catch (e){}
	WindowHeight(0);setTimeout("WindowHeight(-1)",500);
});


// 检测表单
function CheckForm(){
	if ($id('typeID').value==""){ alert("请选择产品类型！");$id('typeID').focus();return false; }
	if ($id('theme').value==""){ alert("请选择产品名称！");$id('theme').focus();return false; }
	var useTimeNum = 0;
	for (var i=0; i<$name('useTimeStr[]').length; i++){
		if ($name('useTimeStr[]')[i].checked){ useTimeNum++; }
	}
	if (useTimeNum == 0){ alert("请选择允许开通期限！");return false; }

	if (ToFloat($id('priceMonth').value)==0){ alert("月付价格不能为空或为0！");$id('priceMonth').focus();return false; }
	if (ToFloat($id('costMonth').value)==0){ alert("月付成本不能为空或为0！");$id('costMonth').focus();return false; }
	if (ToFloat($id('rateMonth').value)==0){ alert("月付费率不能为空或为0！");$id('rateMonth').focus();return false; }
	if ($id('uts_day').checked){
		if (ToFloat($id('priceDay').value)==0){ alert("日付价格不能为空或为0！");$id('priceDay').focus();return false; }
		if (ToFloat($id('costDay').value)==0){ alert("日付成本不能为空或为0！");$id('costDay').focus();return false; }
		if (ToFloat($id('rateDay').value)==0){ alert("日付费率不能为空或为0！");$id('rateDay').focus();return false; }
	}
	if ($id('uts_week').checked){
		if (ToFloat($id('priceWeek').value)==0){ alert("周付价格不能为空或为0！");$id('priceWeek').focus();return false; }
		if (ToFloat($id('costWeek').value)==0){ alert("周付成本不能为空或为0！");$id('costWeek').focus();return false; }
		if (ToFloat($id('rateWeek').value)==0){ alert("周付费率不能为空或为0！");$id('rateWeek').focus();return false; }
	}
	if ($id('uts_3month').checked){
		if (ToFloat($id('price3Month').value)==0){ alert("季付价格不能为空或为0！");$id('price3Month').focus();return false; }
		if (ToFloat($id('cost3Month').value)==0){ alert("季付成本不能为空或为0！");$id('cost3Month').focus();return false; }
		if (ToFloat($id('rate3Month').value)==0){ alert("季付费率不能为空或为0！");$id('rate3Month').focus();return false; }
	}
	if ($id('uts_6month').checked){
		if (ToFloat($id('price6Month').value)==0){ alert("半年付价格不能为空或为0！");$id('price6Month').focus();return false; }
		if (ToFloat($id('cost6Month').value)==0){ alert("半年付成本不能为空或为0！");$id('cost6Month').focus();return false; }
		if (ToFloat($id('rate6Month').value)==0){ alert("半年付费率不能为空或为0！");$id('rate6Month').focus();return false; }
	}
	if ($id('uts_year').checked){
		if (ToFloat($id('priceYear').value)==0){ alert("一年付价格不能为空或为0！");$id('priceYear').focus();return false; }
		if (ToFloat($id('costYear').value)==0){ alert("一年付成本不能为空或为0！");$id('costYear').focus();return false; }
		if (ToFloat($id('rateYear').value)==0){ alert("一年付费率不能为空或为0！");$id('rateYear').focus();return false; }
	}
	if ($id('uts_2year').checked){
		if (ToFloat($id('price2Year').value)==0){ alert("二年付价格不能为空或为0！");$id('price2Year').focus();return false; }
		if (ToFloat($id('cost2Year').value)==0){ alert("二年付成本不能为空或为0！");$id('cost2Year').focus();return false; }
		if (ToFloat($id('rate2Year').value)==0){ alert("二年付费率不能为空或为0！");$id('rate2Year').focus();return false; }
	}
	if ($id('uts_3year').checked){
		if (ToFloat($id('price3Year').value)==0){ alert("三年付价格不能为空或为0！");$id('price3Year').focus();return false; }
		if (ToFloat($id('cost3Year').value)==0){ alert("三年付成本不能为空或为0！");$id('cost3Year').focus();return false; }
		if (ToFloat($id('rate3Year').value)==0){ alert("三年付费率不能为空或为0！");$id('rate3Year').focus();return false; }
	}
	try{
		if ($id('uts_4year').checked){
			if (ToFloat($id('price4Year').value)==0){ alert("四年付价格不能为空或为0！");$id('price4Year').focus();return false; }
			if (ToFloat($id('cost4Year').value)==0){ alert("四年付成本不能为空或为0！");$id('cost4Year').focus();return false; }
			if (ToFloat($id('rate4Year').value)==0){ alert("四年付费率不能为空或为0！");$id('rate4Year').focus();return false; }
		}
		if ($id('uts_5year').checked){
			if (ToFloat($id('price5Year').value)==0){ alert("五年付价格不能为空或为0！");$id('price5Year').focus();return false; }
			if (ToFloat($id('cost5Year').value)==0){ alert("五年付成本不能为空或为0！");$id('cost5Year').focus();return false; }
			if (ToFloat($id('rate5Year').value)==0){ alert("五年付费率不能为空或为0！");$id('rate5Year').focus();return false; }
		}
	}catch (e){}
	return true
}


// 检测付款方式
function CheckUseTimeStr(){
	for (var i=0; i<$name('useTimeStr[]').length; i++){
		if ($name('useTimeStr[]')[i].value != '|24hour|' && $name('useTimeStr[]')[i].value != '|48hour|' && $name('useTimeStr[]')[i].value != '|month|'){
			if ($name('useTimeStr[]')[i].checked){
				$id('box_'+ $name('useTimeStr[]')[i].value.replace(/\|/g,'')).style.display = '';
			}else{
				$id('box_'+ $name('useTimeStr[]')[i].value.replace(/\|/g,'')).style.display = 'none';
			}
		}
	}
}


// 自动计算
function CalcPriceCost(){
	if (ToFloat($id('priceMonth').value)==0){ alert("月付价格不能为空或为0！");$id('priceMonth').focus();return false; }
	if (ToFloat($id('costMonth').value)==0){ alert("月付成本不能为空或为0！");$id('costMonth').focus();return false; }
	if (ToFloat($id('rateMonth').value)==0){ alert("月付费率不能为空或为0！");$id('rateMonth').focus();return false; }
	$id('priceDay').value	= formatFlt2(accDiv(accMul($id('priceMonth').value,$id('rateDay').value),$id('rateMonth').value));
	$id('costDay').value	= formatFlt2(accDiv(accMul($id('costMonth').value,$id('rateDay').value),$id('rateMonth').value));
	$id('priceWeek').value	= formatFlt2(accDiv(accMul($id('priceMonth').value,$id('rateWeek').value),$id('rateMonth').value));
	$id('costWeek').value	= formatFlt2(accDiv(accMul($id('costMonth').value,$id('rateWeek').value),$id('rateMonth').value));
	$id('price3Month').value= formatFlt2(accDiv(accMul($id('priceMonth').value,$id('rate3Month').value),$id('rateMonth').value));
	$id('cost3Month').value	= formatFlt2(accDiv(accMul($id('costMonth').value,$id('rate3Month').value),$id('rateMonth').value));
	$id('price6Month').value= formatFlt2(accDiv(accMul($id('priceMonth').value,$id('rate6Month').value),$id('rateMonth').value));
	$id('cost6Month').value	= formatFlt2(accDiv(accMul($id('costMonth').value,$id('rate6Month').value),$id('rateMonth').value));
	$id('priceYear').value	= formatFlt2(accDiv(accMul($id('priceMonth').value,$id('rateYear').value),$id('rateMonth').value));
	$id('costYear').value	= formatFlt2(accDiv(accMul($id('costMonth').value,$id('rateYear').value),$id('rateMonth').value));
	$id('price2Year').value	= formatFlt2(accDiv(accMul($id('priceMonth').value,$id('rate2Year').value),$id('rateMonth').value));
	$id('cost2Year').value	= formatFlt2(accDiv(accMul($id('costMonth').value,$id('rate2Year').value),$id('rateMonth').value));
	$id('price3Year').value	= formatFlt2(accDiv(accMul($id('priceMonth').value,$id('rate3Year').value),$id('rateMonth').value));
	$id('cost3Year').value	= formatFlt2(accDiv(accMul($id('costMonth').value,$id('rate3Year').value),$id('rateMonth').value));
	$id('price4Year').value	= formatFlt2(accDiv(accMul($id('priceMonth').value,$id('rate4Year').value),$id('rateMonth').value));
	$id('cost4Year').value	= formatFlt2(accDiv(accMul($id('costMonth').value,$id('rate4Year').value),$id('rateMonth').value));
	$id('price5Year').value	= formatFlt2(accDiv(accMul($id('priceMonth').value,$id('rate5Year').value),$id('rateMonth').value));
	$id('cost5Year').value	= formatFlt2(accDiv(accMul($id('costMonth').value,$id('rate5Year').value),$id('rateMonth').value));
}

// 计算单个费率
function CalcRate(str){
	if (ToFloat($id('priceMonth').value)==0){ alert("月付价格不能为空或为0！");$id('priceMonth').focus();return false; }
	switch (str){
		case 'day':
			if (ToFloat($id('priceDay').value)==0){ alert("日付价格不能为空或为0！");$id('priceDay').focus();return false; }
			$id('rateDay').value	= formatFlt4(accDiv($id('priceDay').value,$id('priceMonth').value));
			break;

		case 'week':
			if (ToFloat($id('priceWeek').value)==0){ alert("周付价格不能为空或为0！");$id('priceWeek').focus();return false; }
			$id('rateWeek').value	= formatFlt4(accDiv($id('priceWeek').value,$id('priceMonth').value));
			break;

		case '3month':
			if (ToFloat($id('price3Month').value)==0){ alert("季付价格不能为空或为0！");$id('price3Month').focus();return false; }
			$id('rate3Month').value	= formatFlt4(accDiv($id('price3Month').value,$id('priceMonth').value));
			break;

		case '6month':
			if (ToFloat($id('price6Month').value)==0){ alert("半年付价格不能为空或为0！");$id('price6Month').focus();return false; }
			$id('rate6Month').value	= formatFlt4(accDiv($id('price6Month').value,$id('priceMonth').value));
			break;

		case 'year':
			if (ToFloat($id('priceYear').value)==0){ alert("年付价格不能为空或为0！");$id('priceYear').focus();return false; }
			$id('rateYear').value	= formatFlt4(accDiv($id('priceYear').value,$id('priceMonth').value));
			break;

		case '2year':
			if (ToFloat($id('price2Year').value)==0){ alert("两年付价格不能为空或为0！");$id('price2Year').focus();return false; }
			$id('rate2Year').value	= formatFlt4(accDiv($id('price2Year').value,$id('priceMonth').value));
			break;

		case '3year':
			if (ToFloat($id('price3Year').value)==0){ alert("三年付价格不能为空或为0！");$id('price3Year').focus();return false; }
			$id('rate3Year').value	= formatFlt4(accDiv($id('price3Year').value,$id('priceMonth').value));
			break;

		case '4year':
			if (ToFloat($id('price4Year').value)==0){ alert("四年付价格不能为空或为0！");$id('price4Year').focus();return false; }
			$id('rate4Year').value	= formatFlt4(accDiv($id('price4Year').value,$id('priceMonth').value));
			break;

		case '5year':
			if (ToFloat($id('price5Year').value)==0){ alert("五年付价格不能为空或为0！");$id('price5Year').focus();return false; }
			$id('rate5Year').value	= formatFlt4(accDiv($id('price5Year').value,$id('priceMonth').value));
			break;

	}
}


// 设置产品名称
function SetThemeValue(){
	if ($id('theme').value == ''){ $id('theme').value=SelectGetText('typeID').replace(GetSignStr(SelectGetText('typeID'),'（公司','）',true,true),''); }
}


// 读取产品类型名称
function LoadVpsTypeText(){
	if ($id('typeID').value == ''){ alert("请先选择产品名称，再点击！");$id('typeID').focus();return false; }
	$id('theme').value = SelectGetText('typeID').replace(GetSignStr(SelectGetText('typeID'),'（公司','）',true,true),'');
}